/*
* INSANE - Interactive Structural Analysis Environment
*
* Copyright (C) 2003-2005
* Universidade Federal de Minas Gerais
* Escola de Engenharia
* Departamento de Engenharia de Estruturas
* 
* Author's email :    insane@dees.ufmg.br
* Author's website :  http://www.dees.ufmg.br/insane
* 
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or any later version.
* 
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
* 
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/
/*
 * Created on 12/08/2005
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package br.ufmg.dees.insane.draw;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Rectangle;
import java.util.Vector;

/**
 * @author Samuel Silva Penna
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class CaptionDraw extends Draw{

	public boolean captionOn = true;
	public static boolean isLineOn = true;
	public static boolean isMarksOn = true;
	public int		captionsNumber;
	public String[]	label;
	public byte 	labelPlace;
	public int[] 		labelSize; 
	public byte[]  	labelStyle;
	public String[]	labelFont;
	public String 	title;
	public byte 	titlePlace;
	public int 		titleSize;
	public byte  	titleStyle;
	public String 	titleFont;
	public byte[] markType;
	public MarkDraw[] mark;
	public int[] markSize;
	public Color titleColor;
	public Color[] lineColor;
	public Color[] markColor;
	public Color[] labelColor;
	public float[] lineWidth;
	public BasicStroke[] gList;
	
	public CaptionDraw(Point loc, String title, int capNum, String[] lb, int[] lbSize) {
		this(loc,title,capNum,lb,lbSize,null);

    }
	public CaptionDraw(Point loc, String title, int capNum, String[] lb, int[] lbSize, Object represents) {
		this.title = title;
		this.captionsNumber = capNum;
		this.gList = new BasicStroke[this.captionsNumber];
		this.lineWidth = new float[this.captionsNumber];
		this.mark = new MarkDraw[this.captionsNumber];
		this.markSize = new int[this.captionsNumber];
		this.lineColor = new Color[this.captionsNumber];
		this.markColor = new Color[this.captionsNumber];
		this.labelColor = new Color[this.captionsNumber];
		this.label = new String[captionsNumber];
		this.labelFont = new String[captionsNumber];
		this.labelSize = lbSize;
		this.labelStyle = new byte[captionsNumber];
		this.label = lb;
		this.labelSize = lbSize;
		this.setLocation(loc);
        //this.setSize(new Dimension(size,size));
        this.setRepresents(represents);
    }
	
	public CaptionDraw(){
		
	}
	
	/**
     * Draws in a given Graphics.
     * @see   java.awt.Graphics
     */
    public void draw(Graphics2D g2) {
    	
        int x = this.getLocation().x;
        int y = this.getLocation().y;
        
        g2.setColor(titleColor);
		g2.setFont(new Font(this.titleFont, this.titleStyle, this.titleSize));
		FontMetrics metrics = g2.getFontMetrics();
		int txtHeight = metrics.getHeight();
		x +=50; 
        y +=txtHeight;
		g2.drawString(title, x, y);
		
		x +=20;
		y +=10;
		
		for(int i=0;i<captionsNumber;i++){

			g2.setFont(new Font(this.labelFont[i], this.labelStyle[i], this.labelSize[i]));
			FontMetrics metrics2 = g2.getFontMetrics();
			float txtLabelHeight = (float)metrics2.getHeight();
			if(isLineOn){
				g2.setColor(lineColor[i]);
				g2.setStroke(gList[i]);
				g2.drawLine(x-20, y+(int)txtLabelHeight/2, x+20, y+(int)txtLabelHeight/2);
			}
			if(isMarksOn){
				mark[i].setSize(new Dimension(this.markSize[i],this.markSize[i])); 
				mark[i].setLocation(new Point(x, y+(int)txtLabelHeight/2));
				g2.setColor(markColor[i]);
				g2.setStroke(new BasicStroke(lineWidth[i],BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
				this.mark[i].setLabelOn(false);
				mark[i].draw(g2);
			}
			g2.setColor(labelColor[i]);
			g2.drawString(this.label[i],(float)(x+35),(float)((float)y+txtLabelHeight/1.35f));
			
			y +=metrics2.getHeight()+5;
		}
		
    } 
	 /**
     * Returns the draw bounds in device units.
     *
     * @return the draw bounds
     */
    public Rectangle getBounds() {
        
        int x1 = this.getLocation().x;
        int y1 = this.getLocation().y;
        int x2 = this.getSize().width;
        int y2 = this.getSize().height;
        
        Rectangle rect = new Rectangle(x1, y1, x2 - x1, y2 - y1);
        
        return rect;
    }
    
    public Vector<Object> getShapes() {
        return null;
    }
}